<?php

/**
 * Created by PhpStorm.
 * Author: kaodou
 * Date: 2018/3/9
 * Time: 14:09
 */
namespace App\Http\Admin\Buyers\Controllers;

use Framework\BaseClass\Http\Admin\Controller;
use App\Http\Admin\Website\Models\Menu;
use App\Eloquent\Ygt\Buyers;
use App\Engine\Customer as CustomerEngine;

class IndexController extends Controller
{
    protected $modelName = 'Buyers';
    protected $company = true;

    public function __construct()
    {
        parent::__construct();
        $this->model = new Buyers();

    }

    protected function _hdata($result){
        $result->transform(function ($item, $key) {
            $item->customer_name = isset($item->customer['customer_name'])?$item->customer['customer_name']:'';
            return $item;
        });
        return $result;
    }
    protected function _honedata($info){
        $info->customer_name = isset($info->customer->customer_name)?$info->customer->customer_name:'';
        return $info;
    }

    protected function _cdata(){
        $cdata = [
            'customer_id'=>request('customer_id')
        ];
        return $cdata;
    }

    protected function _where()
    {
        $where = [];
        if($custoemrId = request('customer_id')){
            $where['customer_id'] = $custoemrId;
        }
        return $where;
    }
    protected function _vdata()
    {
        $customerId = request('customer_id');
        return compact('customerId');
    }

    protected function _vdataAdd()
    {
        $customerId = request('customer_id');
        $customerName = CustomerEngine::getNameById($customerId);
        return compact('customerId','customerName');
    }

}